package com.example.song.wlms.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.example.song.wlms.R;
import com.example.song.wlms.bean.ReconmmendData;
import com.example.song.wlms.widget.GlideYuanjiaoTransform;

import java.util.List;

/**
 * Created by song on 2017/2/12.
 */

public class SpecialGridAdapter extends BaseAdapter {
    private List<ReconmmendData.DataBean.SPECIALBean> list;
    private Context context;

    public SpecialGridAdapter(List<ReconmmendData.DataBean.SPECIALBean> list, Context context) {
        this.list = list;
        this.context = context;
    }

    @Override
    public int getCount() {
        return list != null ? list.size() : 0;
    }

    @Override
    public Object getItem(int position) {
        return list.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder = null;
        if (convertView == null) {
            convertView = LayoutInflater.from(context).inflate(R.layout.zhuan_item, parent, false);
            holder = new ViewHolder();
            holder.imageView = (ImageView) convertView.findViewById(R.id.zhuanImage);
            holder.title = (TextView) convertView.findViewById(R.id.zhuanTitle);
            holder.text = (TextView) convertView.findViewById(R.id.zhuanText);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }
        Glide.with(context).load(list.get(position).getImg()).placeholder(R.mipmap.bg_cos_avatar).transform(new GlideYuanjiaoTransform(context)).into(holder.imageView);
        holder.title.setText(list.get(position).getTitle());
        holder.text.setText(list.get(position).getDesc());
        return convertView;
    }

    class ViewHolder {
        ImageView imageView;
        TextView title, text;
    }
}
